import { getGrade } from '@/utils/enum'

export interface User {
  id: number
  openId: string
  nickname?: string
  school: string
  major: string
  grade: string | number
  // 人设
  role: string
  // 性格
  personality: string
  // 偏向
  preference: string
  email: string
  phone: string
  introduction: string

  schoolcode: number
  gradecode: number
  majorcode: number
}

export interface BackendUser {
  id: number
  openid: string
  nickname?: string
  schoolname?: string
  major?: number
  majorName?: string
  grade: number
  school: number
  persona?: string
  personality?: string
  projectOrientation?: string
  email?: string
  phone?: string
  introduction?: string
}

export function mapUserFromBackend(element: BackendUser): User {
  return {
    id: element.id,
    openId: element.openid,
    nickname: element.nickname,
    school: element.schoolname || '未知',
    major: element.majorName || '未知',
    grade: getGrade(element.grade),
    role: element.persona || '未知',
    personality: element.personality || '未知',
    preference: element.projectOrientation || '未知',
    email: element.email || '无邮箱',
    phone: element.phone || '无电话',
    introduction: element.introduction || '无介绍',

    schoolcode: element.school,
    gradecode: element.grade,
    majorcode: element.major,
  }
}
